package com.mac.demo.action;

import com.mac.demo.service.IUserInfo;
import com.mac.demo.vo.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/demo")
public class DemoAction {
    private final Logger log =  LoggerFactory.getLogger(this.getClass());

    @Autowired
    private IUserInfo iUserInfo;

    @RequestMapping("/{id}")
    @ResponseBody
    public String resoultMap(@PathVariable String id) {
        return id;
    }

    @RequestMapping("/list")
    public String  listUser(Model model, User vo) {
        List<User> userList = iUserInfo.queryInfo(vo);
        model.addAttribute("users", userList);
        return "views/demo/list";
    }

    @RequestMapping("/bootstrap")
    public String  bootstrapUser(Model model, User vo) {
        List<User> userList = iUserInfo.queryInfo(vo);
        Map<String, Object> map1 = new HashMap<String, Object>();
        map1.put("uri", "/images/002.jpg");
        map1.put("title", "嗨屁狗");
        map1.put("alt", "嗨屁狗");
        Map<String, Object> map2 = new HashMap<String, Object>();
        map2.put("uri", "/images/003.jpg");
        map2.put("title", "霹雳海报-素还真");
        map2.put("alt", "霹雳海报-素还真");
        Map<String, Object> map3 = new HashMap<String, Object>();
        map3.put("uri", "/images/004.jpg");
        map3.put("title", "霹雳海报-醉饮黄龙");
        map3.put("alt", "霹雳海报-醉饮黄龙");
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        list.add(map1);
        list.add(map2);
        list.add(map3);
        model.addAttribute("users", userList);
        model.addAttribute("items", list);
        return "views/demo/bootstrap";
    }
}
